// pages/result/result.js
const app = getApp()
import Dialog from '@vant/weapp/dialog/dialog';

import {apiorderUserDetail,apiorderUserPayVerify} from '../../utils/api.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:'',
    businessId:'',
    orderInfo:{},

    detailData:'',
    showShopList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let that = this
    that.setData({
      orderId:options.orderId,
      businessId:options.businessId
    })
    this.GetCouponScan();
  },
  GetCouponScan(){
    apiorderUserDetail({id:this.data.orderId}).then(res=>{
       this.setData({
        detailData:res.data,
				showShopList:res.data.goodsInfo
       })
    })
  },
  // 核销
  orderEd(){
    let that = this
    if (that.data.detailData.status === 2) {
      wx.showToast({
        title: '已核销',
        icon: 'none',
        duration: 2000
      });
    } else {
      this.orderRequest()
    }
  },

  orderRequest() {
    let that = this;
    apiorderUserPayVerify({orderId:this.data.detailData.id,storeId:this.data.businessId}).then(res=>{
     if(res.code==200){
           wx.showToast({
              title: '核销成功',
              icon: 'none',
              duration: 2000
            });
            setTimeout(function(){
              wx.navigateBack({
                delta: 1,
              })
            },1500);
     }else{
      wx.showToast({
            icon: "none",
            title: res.message,
            duration: 2000
          })
          setTimeout(function(){
            wx.navigateBack({
              delta: 1,
            })
          },1500);
     }
    })
    // http.post('/api/store/v1/appointment/update/status', {
    //   id: that.data.orderId,
    //   status: 1 //使用成功
    // }).then(res => {
    //   console.log(res,"修改订单状态")
    //   if(res.code == 200 ){
    //     wx.showToast({
    //       title: '到店成功',
    //       icon: 'none',
    //       duration: 2000
    //     });
    //     setTimeout(function(){
    //       wx.navigateBack({
    //         delta: 1,
    //       })
    //     },1500);
    //   } else {
    //     wx.showToast({
    //       icon: "none",
    //       title: res.message,
    //       duration: 2000
    //     })
    //     setTimeout(function(){
    //       wx.navigateBack({
    //         delta: 1,
    //       })
    //     },1500);
    //   }
    // })
  }
})